package com.demo2do.fms.admin.entity.search.supplier;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

import java.util.Map;

/**
 * 查询供方所用条件
 * Created by zhonghui on 2017/6/27.
 */
public class TransportationCompanySearch implements QueryBuilder {

    /**
     * 公司代码
     */
    private String code;

    /**
     * 公司名称
     */
    private String name;

    private QueryOrder queryOrder;

    private QueryFilter queryFilter;

    /**
     * Instantiates a new Transportation company search.
     */
    public TransportationCompanySearch() {
        queryOrder = new QueryOrder();
    }

    /*
     * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter().addEquals("code", code)
                    .addEquals("name", name);
        }
        return queryFilter;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /*
         * (non-Javadoc)
         * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
         */
    public String buildSentenceTemplate() {

        String sentence = "FROM Organization WHERE disabled = false" + getPreparedFilter(false).clauseSentence() + queryOrder.sentence();

        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }

    /**
     * Gets code.
     *
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * Gets name.
     *
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Gets query filter.
     *
     * @return the query filter
     */
    public QueryFilter getQueryFilter() {
        return getPreparedFilter(false);
    }

    /**
     * Sets code.
     *
     * @param code the code
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * Sets name.
     *
     * @param name the name
     */
    public void setName(String name) {
        this.name = name;
    }


}
